package entity

import (
	dom "a-common/domain"
	"time"
	// "github.com/vmihailenco/msgpack"
)

const (
	SEX_MAN    = "0"
	SEX_WOMAN  = "1"
	SEX_UNKNOW = "2"
)

// SysUser 系统用户表
type SysUser struct {
	UserId         int64     `xorm:"pk autoincr notnull"`        // 用户ID
	Username       string    `xorm:"varchar(20) notnull unique"` // 用户账号
	Nickname       string    `xorm:"varchar(50) notnull"`        // 用户昵称
	Avatar         string    `xorm:"varchar(255)"`               // 头像地址
	Email          string    `xorm:"varchar(50)"`                // 用户邮箱
	Phone          string    `xorm:"varchar(20)"`                // 电话号码
	LastLoginTime  time.Time // 最新登录时间
	LoginIp        string    `xorm:"varchar(128)"`            // 最后登录IP
	Password       string    `xorm:"varchar(100) notnull"`    // 密码
	Status         string    `xorm:"varchar(1) default('1')"` // 状态:0=禁用,1=启用
	dom.BaseStruct `xorm:"extends"`
}

// func (m *SysUserVo) MarshalBinary() ([]byte, error) {
// 	return json.Marshal(m)
// }

// func (m *SysUserVo) UnmarshalBinary(data []byte) error {
// 	return msgpack.Unmarshal(data, m)
// }

// SysUserVo 映射
type SysUserVo struct {
	UserId        int64    `json:"userId,omitempty" xorm:"pk"`
	Username      string   `json:"username,omitempty"`
	Nickname      string   `json:"nickname,omitempty"`
	Avatar        string   `json:"avatar,omitempty"`
	Email         string   `json:"email,omitempty"`
	Phone         string   `json:"phone,omitempty"`
	LastLoginTime dom.Time `json:"loginDate" form:"loginDate"`
	LoginIp       string   `json:"loginIp" form:"loginIp"`
	Password      string   `json:"-"`
	Status        string   `json:"status,omitempty"`
}

// SysUserPageVo 页面
type SysUserPageVo struct {
	SysUserVo    `xorm:"extends"`
	dom.BaseJson `xorm:"extends"`
}

// UserDto 传输
type UserDto struct {
	SysUserPageVo
	Params dom.ParamTime `json:"params"`
	dom.PageDto

	RoleId  int64   `json:"roleId" xorm:"-"`
	UserIds []int64 `json:"userIds" xorm:"-"`
	RoleIds []int64 `json:"roleIds" xorm:"-"`
	PostIds []int64 `json:"postIds" xorm:"-"`

	OldPassword string `json:"oldPassword" xorm:"-"`
	NewPassword string `json:"newPassword" xorm:"-"`
}

func (m *UserDto) Validator() error {
	if m.PageNum < 1 {
		m.PageNum = 1
	}
	if m.PageSize < 1 {
		m.PageSize = 10
	}
	return nil
}

// SysUserExportVo 导出
type SysUserExportVo struct {
	UserId      int64    `excel:"name:用户ID;" xorm:"pk"`
	UserName    string   `excel:"name:登录名称;"`
	NickName    string   `excel:"name:用户名称;"`
	Email       string   `excel:"name:用户邮箱;"`
	Phonenumber string   `excel:"name:手机号码;"`
	Sex         string   `excel:"name:用户性别;replace:0_男,1_女,2_未知;"`
	Status      string   `excel:"name:帐号状态;replace:0_正常,1_停用;"`
	LoginIp     string   `excel:"name:最后登录IP;"`
	LoginDate   dom.Time `excel:"name:最后登录时间;"`
	DeptName    string   `excel:"name:部门名称;"`
	Leader      string   `excel:"name:部门负责人;"`
}

// SysUserImportVo 导入
type SysUserImportVo struct {
	UserId      int64  `json:"userId,omitempty" excel:"name:用户ID;" xorm:"pk"`
	DeptId      int64  `json:"deptId,omitempty" excel:"name:部门编号;"`
	UserName    string `json:"userName,omitempty" excel:"name:登录名称;"`
	NickName    string `json:"nickName,omitempty" excel:"name:用户名称;"`
	Email       string `json:"email,omitempty" excel:"name:用户邮箱;"`
	Phonenumber string `json:"phonenumber,omitempty" excel:"name:手机号码;"`
	Sex         string `json:"sex" excel:"name:用户性别;replace:0_男,1_女,2_未知;"`
	Status      string `json:"status,omitempty" excel:"name:帐号状态;replace:0_正常,1_停用;"`
}

// SysUserSelectListVo 用户下拉列表
type SysUserSelectListVo struct {
	UserId   int64  `json:"userId,omitempty" xorm:"pk"`
	UserName string `json:"userName,omitempty"`
}
